#
# Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
#
# GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
# Author: Shawn.Tan
# Date: 2025.10.28
#
# History: Initial Version 2025.10.28
#
#
from VectorTestSequence import VectorLoadStoreTestSequence
from gpgpu.EnvGPGPU import EnvGPGPU
from gpgpu.GenThreadGPGPU import GenThreadGPGPU
import re


# This test verifies that unit-stride segment load and store instructions can be generated and
# executed successfully.
class MainSequence(VectorLoadStoreTestSequence):
    def __init__(self, aGenThread, aName=None):
        super().__init__(aGenThread, aName)

        instr_base_list = (
            "VLSEG%dE%d.V##CALM",
            "VLSEG%dE%dFF.V##CALM",
            "VSSEG%dE%d.V##CALM",
        )

        self._mInstrList = []
        for instr_base in instr_base_list:
            for field_count in range(2, 9):
                for eew in (8, 16, 32, 64):
                    self._mInstrList.append(instr_base % (field_count, eew))

    # Return a list of test instructions to randomly choose from.
    def _getInstructionList(self):
        return self._mInstrList

    # Calculate the largest register count for the given instruction's operands.
    #
    #  @param aInstr The name of the instruction.
    def _calculateMaxRegisterCount(self, aInstr):
        match = re.fullmatch(r"V(L|S)SEG(\d)E\d+(FF)?\.V\#\#CALM", aInstr)
        field_count = int(match.group(2))

        return self.calculateEmul(aInstr) * field_count


MainSequenceClass = MainSequence
GenThreadClass = GenThreadGPGPU
EnvClass = EnvGPGPU
